package everyday;

import java.util.Arrays;

public class T1605 {
    public int[][] restoreMatrix(int[] rowSum, int[] colSum) {
        int rowlen = rowSum.length;
        int collen = colSum.length;
        int[][] re = new int[rowlen][collen];
        for (int[] r : re) {
            Arrays.fill(r, 0);
        }

        int i = 0, j = 0;
        while (i < collen || j < rowlen) {
            if (colSum[i] < rowSum[j]) {
                re[j][i]=colSum[i];
                rowSum[j]-=colSum[i];
                i++;
            }else {
                re[j][i]=rowSum[i];
                colSum[j]-=rowSum[i];
                j++;
            }
        }
        return re;
    }
}
